1
|
|
|
/*jslint |
2
|
|
|
indent: 4 |
3
|
|
|
*/ |
4
|
|
|
|
5
|
|
|
/*global |
6
|
|
|
$, google, Lines, Markers, Conversion, Cookies, Coordinates, trackMarker, mytrans, showAlert, id2alpha |
7
|
|
|
*/ |
8
|
|
|
|
9
|
|
|
//var boundariesLayer = null; |
10
|
|
|
//var boundariesLayerShown = false; |
11
|
|
|
var map = null; |
12
|
|
|
var copyrightDiv; |
13
|
|
|
|
14
|
|
|
var theMarkers = new Markers(); |
15
|
|
|
|
16
|
|
|
var CLAT_DEFAULT = 51.163375; |
17
|
|
|
var CLON_DEFAULT = 10.447683; |
18
|
|
|
var ZOOM_DEFAULT = 12; |
19
|
|
|
var MAPTYPE_DEFAULT = "OSM"; |
20
|
|
|
var RADIUS_DEFAULT = 0; |
21
|
|
|
|
22
|
|
|
|
23
|
|
|
function enterEditMode(id) { |
24
|
|
|
'use strict'; |
25
|
|
|
|
26
|
|
|
trackMarker('edit'); |
27
|
|
|
var m = theMarkers.getById(id); |
28
|
|
|
|
29
|
|
|
$('#edit_name' + m.getAlpha()).val(m.getName()); |
30
|
|
|
$('#edit_coordinates' + m.getAlpha()).val(Coordinates.toString(m.getPosition())); |
31
|
|
|
$('#edit_circle' + m.getAlpha()).val(m.getRadius()); |
32
|
|
|
|
33
|
|
|
$('#dynview' + id).hide(); |
34
|
|
|
$('#dynedit' + id).show(); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
|
38
|
|
|
function leaveEditMode(id, takenew) { |
39
|
|
|
'use strict'; |
40
|
|
|
|
41
|
|
|
if (takenew) { |
42
|
|
|
var m = theMarkers.getById(id), |
43
|
|
|
name = $('#edit_name' + m.getAlpha()).val(), |
44
|
|
|
name_ok = /^([a-zA-Z0-9-_]*)$/.test(name), |
45
|
|
|
s_coordinates = $('#edit_coordinates' + m.getAlpha()).val(), |
46
|
|
|
coordinates = Coordinates.fromString(s_coordinates), |
47
|
|
|
s_radius = $('#edit_circle' + m.getAlpha()).val(), |
48
|
|
|
radius = Conversion.getInteger(s_radius, 0, 100000000000), |
49
|
|
|
errors = []; |
50
|
|
|
|
51
|
|
|
if (!name_ok) { |
52
|
|
|
errors.push(mytrans("sidebar.markers.error_badname").replace(/%1/, name)); |
53
|
|
|
} |
54
|
|
|
if (!coordinates) { |
55
|
|
|
errors.push(mytrans("sidebar.markers.error_badcoordinates").replace(/%1/, s_coordinates)); |
56
|
|
|
} |
57
|
|
|
if (radius === null) { |
58
|
|
|
errors.push(mytrans("sidebar.markers.error_badradius").replace(/%1/, s_radius)); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
if (errors.length > 0) { |
62
|
|
|
showAlert(mytrans("dialog.error"), errors.join("<br /><br />")); |
63
|
|
|
} else { |
64
|
|
|
m.setNamePositionRadius(name, coordinates, radius); |
65
|
|
|
$('#dynview' + id).show(); |
66
|
|
|
$('#dynedit' + id).hide(); |
67
|
|
|
} |
68
|
|
|
} else { |
69
|
|
|
$('#dynview' + id).show(); |
70
|
|
|
$('#dynedit' + id).hide(); |
71
|
|
|
} |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
|
75
|
|
|
function createMarkerDiv(id) { |
76
|
|
|
'use strict'; |
77
|
|
|
|
78
|
|
|
var alpha = id2alpha(id), |
79
|
|
|
iconw = 33, |
80
|
|
|
iconh = 37, |
81
|
|
|
offsetx = (id % 26) * iconw, |
82
|
|
|
offsety = Math.floor(id / 26) * iconh; |
83
|
|
|
|
84
|
|
|
return "<div id=\"dyn" + id + "\">" + |
85
|
|
|
"<table id=\"dynview" + id + "\" style=\"width: 100%; vertical-align: middle;\">\n" + |
86
|
|
|
" <tr>\n" + |
87
|
|
|
" <td rowspan=\"3\" style=\"vertical-align: top\">\n" + |
88
|
|
|
" <span style=\"width:" + iconw + "px; height:" + iconh + "px; float: left; display: block; background-image: url(img/markers.png); background-repeat: no-repeat; background-position: -" + offsetx + "px -" + offsety + "px;\"> </span>\n" + |
89
|
|
|
" </td>\n" + |
90
|
|
|
" <td style=\"text-align: center\"><i class=\"fa fa-map-marker\"></i></td>\n" + |
91
|
|
|
" <td id=\"view_name" + alpha + "\" colspan=\"2\">marker</td>\n" + |
92
|
|
|
" </tr>\n" + |
93
|
|
|
" <tr>\n" + |
94
|
|
|
" <td style=\"text-align: center\"><i class=\"fa fa-globe\"></i></td>\n" + |
95
|
|
|
" <td id=\"view_coordinates" + alpha + "\" colspan=\"2\">N 48° 00.123 E 007° 51.456</td>\n" + |
96
|
|
|
" </tr>\n" + |
97
|
|
|
" <tr>\n" + |
98
|
|
|
" <td style=\"text-align: center\"><i class=\"fa fa-circle-o\"></i></td>\n" + |
99
|
|
|
" <td id=\"view_circle" + alpha + "\">16100 m</td>\n" + |
100
|
|
|
" <td>\n" + |
101
|
|
|
" <div class=\"btn-group\" style=\"padding-bottom: 2px; padding-top: 2px; float: right\">\n" + |
102
|
|
|
" <button class=\"my-button btn btn-mini btn-warning\" data-i18n=\"[title]sidebar.markers.edit_marker\" type=\"button\" onclick=\"enterEditMode(" + id + ");\"><i class=\"fa fa-edit\"></i></button>\n" + |
103
|
|
|
" <button class=\"my-button btn btn-mini btn-danger\" data-i18n=\"[title]sidebar.markers.delete_marker\" type=\"button\" onClick=\"theMarkers.removeById(" + id + ")\"><i class=\"fa fa-trash-o\"></i></button>\n" + |
104
|
|
|
" <button class=\"my-button btn btn-mini btn-info\" data-i18n=\"[title]sidebar.markers.move_to\" type=\"button\" onClick=\"theMarkers.goto(" + id + ")\"><i class=\"fa fa-search\"></i></button>\n" + |
105
|
|
|
" <button class=\"my-button btn btn-mini btn-warning\" data-i18n=\"[title]sidebar.markers.center\" type=\"button\" onClick=\"theMarkers.center(" + id + ")\"><i class=\"fa fa-crosshairs\"></i></button>\n" + |
106
|
|
|
" <button class=\"my-button btn btn-mini btn-success\" data-i18n=\"[title]sidebar.markers.project\" type=\"button\" onClick=\"projectFromMarker(" + id + ")\"><i class=\"fa fa-location-arrow\"></i></button>\n" + |
107
|
|
|
" </div>\n" + |
108
|
|
|
" </td>\n" + |
109
|
|
|
" </tr>\n" + |
110
|
|
|
"</table>\n" + |
111
|
|
|
"<table id=\"dynedit" + id + "\" style=\"display: none; width: 100%; vertical-align: middle;\">\n" + |
112
|
|
|
" <tr>\n" + |
113
|
|
|
" <td rowspan=\"4\" style=\"vertical-align: top\"><span style=\"width:" + iconw + "px; height:" + iconh + "px; float: left; display: block; background-image: url(img/markers.png); background-repeat: no-repeat; background-position: -" + offsetx + "px -" + offsety + "px;\"> </span>\n" + |
114
|
|
|
" <td style=\"text-align: center; vertical-align: middle;\"><i class=\"icon-map-marker\"></i></td>\n" + |
115
|
|
|
" <td><input id=\"edit_name" + alpha + "\" data-i18n=\"[title]sidebar.markers.name;[placeholder]sidebar.markers.name_placeholder\" class=\"form-control input-block-level\" type=\"text\" style=\"margin-bottom: 0px;\" value=\"n/a\" /></td>\n" + |
116
|
|
|
" </tr>\n" + |
117
|
|
|
" <tr>\n" + |
118
|
|
|
" <td style=\"text-align: center; vertical-align: middle;\"><i class=\"icon-globe\"></i></td>\n" + |
119
|
|
|
" <td><input id=\"edit_coordinates" + alpha + "\" data-i18n=\"[title]sidebar.markers.coordinates;[placeholder]sidebar.markers.coordinates_placeholder\" class=\"form-control input-block-level\" type=\"text\" style=\"margin-bottom: 0px;\" value=\"n/a\" /></td>\n" + |
120
|
|
|
" </tr>\n" + |
121
|
|
|
" <tr>\n" + |
122
|
|
|
" <td style=\"text-align: center; vertical-align: middle;\"><i class=\"icon-circle-blank\"></i></td>\n" + |
123
|
|
|
" <td><input id=\"edit_circle" + alpha + "\" data-i18n=\"[title]sidebar.markers.radius;[placeholder]sidebar.markers.radius_placeholder\" class=\"form-control input-block-level\" type=\"text\" style=\"margin-bottom: 0px;\" value=\"n/a\" /></td>\n" + |
124
|
|
|
" </tr>\n" + |
125
|
|
|
" <tr>\n" + |
126
|
|
|
" <td colspan=\"2\" style=\"text-align: right\">\n" + |
127
|
|
|
" <button class=\"btn btn-small btn-primary\" type=\"button\" onclick=\"javascript: leaveEditMode(" + id + ", true);\" data-i18n=\"dialog.ok\">OK</button>\n" + |
128
|
|
|
" <button class=\"btn btn-small\" type=\"button\" onclick=\"leaveEditMode(" + id + ", false);\" data-i18n=\"dialog.cancel\">CANCEL</button>\n" + |
129
|
|
|
" </td>\n" + |
130
|
|
|
" </tr>\n" + |
131
|
|
|
"</table>" + |
132
|
|
|
"</div>"; |
133
|
|
|
} |
134
|
|
|
|
135
|
|
|
|
136
|
|
|
function newMarker(coordinates, id, radius, name) { |
137
|
|
|
'use strict'; |
138
|
|
|
|
139
|
|
|
if (radius < 0) { |
140
|
|
|
radius = RADIUS_DEFAULT; |
141
|
|
|
} |
142
|
|
|
|
143
|
|
|
if (id < 0 || id >= theMarkers.getSize() || !theMarkers.getById(id).isFree()) { |
144
|
|
|
id = theMarkers.getFreeId(); |
145
|
|
|
} |
146
|
|
|
if (id < 0) { |
147
|
|
|
showAlert( |
148
|
|
|
mytrans("dialog.error"), |
149
|
|
|
mytrans("dialog.toomanymarkers_error.content").replace(/%1/, theMarkers.getSize()) |
150
|
|
|
); |
151
|
|
|
return null; |
152
|
|
|
} |
153
|
|
|
|
154
|
|
|
var alpha = id2alpha(id), |
155
|
|
|
marker, |
156
|
|
|
div, |
157
|
|
|
nextid; |
158
|
|
|
|
159
|
|
|
if (!name || name === "") { |
160
|
|
|
name = "marker_" + alpha; |
161
|
|
|
} |
162
|
|
|
|
163
|
|
|
marker = theMarkers.getById(id); |
164
|
|
|
marker.initialize(map, name, coordinates, radius); |
165
|
|
|
div = createMarkerDiv(id); |
166
|
|
|
|
167
|
|
|
nextid = theMarkers.getNextUsedId(id); |
168
|
|
|
if (nextid < 0) { |
169
|
|
|
$('#dynMarkerDiv').append(div); |
170
|
|
|
} else { |
171
|
|
|
$(div).insertBefore('#dyn' + nextid); |
172
|
|
|
} |
173
|
|
|
|
174
|
|
|
$('#edit_name' + alpha).keydown(function (e) { |
175
|
|
|
if (e.which === 27) { |
176
|
|
|
leaveEditMode(id, false); |
177
|
|
|
} else if (e.which === 13) { |
178
|
|
|
leaveEditMode(id, true); |
179
|
|
|
} |
180
|
|
|
}); |
181
|
|
|
|
182
|
|
|
$('#edit_coordinates' + alpha).keydown(function (e) { |
183
|
|
|
if (e.which === 27) { |
184
|
|
|
leaveEditMode(id, false); |
185
|
|
|
} else if (e.which === 13) { |
186
|
|
|
leaveEditMode(id, true); |
187
|
|
|
} |
188
|
|
|
}); |
189
|
|
|
|
190
|
|
|
$('#edit_circle' + alpha).keydown(function (e) { |
191
|
|
|
if (e.which === 27) { |
192
|
|
|
leaveEditMode(id, false); |
193
|
|
|
} else if (e.which === 13) { |
194
|
|
|
leaveEditMode(id, true); |
195
|
|
|
} |
196
|
|
|
}); |
197
|
|
|
|
198
|
|
|
$('#btnmarkers2').show(); |
199
|
|
|
$('#btnmarkersdelete1').removeAttr('disabled'); |
200
|
|
|
$('#btnmarkersdelete2').removeAttr('disabled'); |
201
|
|
|
|
202
|
|
|
marker.update(); |
203
|
|
|
theMarkers.saveMarkersList(); |
204
|
|
|
Lines.updateLinesMarkerAdded(); |
205
|
|
|
|
206
|
|
|
return marker; |
207
|
|
|
} |
208
|
|
|
|
209
|
|
|
|
210
|
|
|
function projectFromMarker(id) { |
211
|
|
|
'use strict'; |
212
|
|
|
|
213
|
|
|
trackMarker('project'); |
214
|
|
|
|
215
|
|
|
var mm = theMarkers.getById(id), |
216
|
|
|
oldpos = mm.getPosition(); |
217
|
|
|
|
218
|
|
|
showProjectionDialog( |
219
|
|
|
function (data1, data2) { |
220
|
|
|
var angle = Conversion.getFloat(data1, 0, 360), |
221
|
|
|
dist = Conversion.getFloat(data2, 0, 100000000000), |
222
|
|
|
newpos, |
223
|
|
|
newmarker; |
224
|
|
|
|
225
|
|
|
if (angle === null) { |
226
|
|
|
showAlert( |
227
|
|
|
mytrans("dialog.error"), |
228
|
|
|
mytrans("dialog.projection.error_bad_bearing").replace(/%1/, data1) |
229
|
|
|
); |
230
|
|
|
return; |
231
|
|
|
} |
232
|
|
|
|
233
|
|
|
if (dist === null) { |
234
|
|
|
showAlert( |
235
|
|
|
mytrans("dialog.error"), |
236
|
|
|
mytrans("dialog.projection.error_bad_distance").replace(/%1/, data2) |
237
|
|
|
); |
238
|
|
|
return; |
239
|
|
|
} |
240
|
|
|
|
241
|
|
|
newpos = Coordinates.projection_geodesic(oldpos, angle, dist); |
242
|
|
|
newmarker = newMarker(newpos, -1, RADIUS_DEFAULT, null); |
243
|
|
|
if (newmarker) { |
244
|
|
|
showAlert( |
245
|
|
|
mytrans("dialog.information"), |
246
|
|
|
mytrans("dialog.projection.msg_new_marker").replace(/%1/, newmarker.getAlpha()) |
247
|
|
|
); |
248
|
|
|
} |
249
|
|
|
} |
250
|
|
|
); |
251
|
|
|
} |
252
|
|
|
|
253
|
|
|
|
254
|
|
|
function storeCenter() { |
255
|
|
|
'use strict'; |
256
|
|
|
|
257
|
|
|
var c = map.getCenter(); |
258
|
|
|
Cookies.set('clat', c.lat(), {expires: 30}); |
259
|
|
|
Cookies.set('clon', c.lng(), {expires: 30}); |
260
|
|
|
} |
261
|
|
|
|
262
|
|
|
|
263
|
|
|
function storeZoom() { |
264
|
|
|
'use strict'; |
265
|
|
|
|
266
|
|
|
Cookies.set('zoom', map.getZoom(), {expires: 30}); |
267
|
|
|
} |
268
|
|
|
|
269
|
|
|
|
270
|
|
|
function getFeaturesString() { |
271
|
|
|
'use strict'; |
272
|
|
|
|
273
|
|
|
var s = ""; |
274
|
|
|
//if ($('#boundaries').is(':checked')) { s += "b"; } |
275
|
|
|
if ($('#geocaches').is(':checked')) { s += "g"; } |
276
|
|
|
if ($('#hillshading').is(':checked')) { s += "h"; } |
277
|
|
|
if ($('#npa').is(':checked')) { s += "n"; } |
278
|
|
|
if ($('#freifunk').is(':checked')) { s += "f"; } |
279
|
|
|
|
280
|
|
|
return s; |
281
|
|
|
} |
282
|
|
|
|
283
|
|
|
|
284
|
|
|
function getPermalink() { |
285
|
|
|
'use strict'; |
286
|
|
|
|
287
|
|
|
var lat = map.getCenter().lat(), |
288
|
|
|
lng = map.getCenter().lng(); |
289
|
|
|
|
290
|
|
|
return "http://flopp.net/" + |
291
|
|
|
"?c=" + lat.toFixed(6) + ":" + lng.toFixed(6) + |
292
|
|
|
"&z=" + map.getZoom() + |
293
|
|
|
"&t=" + map.getMapTypeId() + |
294
|
|
|
"&f=" + getFeaturesString() + |
295
|
|
|
"&m=" + theMarkers.toString() + |
296
|
|
|
"&d=" + Lines.getLinesText(); |
297
|
|
|
} |
298
|
|
|
|
299
|
|
|
function generatePermalink() { |
300
|
|
|
'use strict'; |
301
|
|
|
|
302
|
|
|
var link = getPermalink(); |
303
|
|
|
showLinkDialog(link); |
304
|
|
|
} |
305
|
|
|
|
306
|
|
|
|
307
|
|
|
function updateCopyrights() { |
308
|
|
|
'use strict'; |
309
|
|
|
|
310
|
|
|
var newMapType = map.getMapTypeId(), |
311
|
|
|
isGoogleMap = true, |
312
|
|
|
copyright = ""; |
313
|
|
|
|
314
|
|
|
Cookies.set('maptype', newMapType, {expires: 30}); |
315
|
|
|
|
316
|
|
|
if (newMapType === "OSM" || newMapType === "OSM/DE") { |
317
|
|
|
isGoogleMap = false; |
318
|
|
|
copyright = "Map data (C) by <a href=\"http://www.openstreetmap.org/\">OpenStreetMap.org</a> and its contributors; <a href=\"http://opendatacommons.org/licenses/odbl/\">Open Database License</a>"; |
319
|
|
|
} else if (newMapType === "OCM") { |
320
|
|
|
isGoogleMap = false; |
321
|
|
|
copyright = "Map data (C) by <a href=\"http://www.openstreetmap.org/\">OpenStreetMap.org</a> and its contributors; <a href=\"http://opendatacommons.org/licenses/odbl/\">Open Database License</a>, tiles (C) by <a href=\"http://opencyclemap.org\">OpenCycleMap.org</a>"; |
322
|
|
|
} else if (newMapType === "OUTD") { |
323
|
|
|
isGoogleMap = false; |
324
|
|
|
copyright = "Map data (C) by <a href=\"http://www.openstreetmap.org/\">OpenStreetMap.org</a> and its contributors; <a href=\"http://opendatacommons.org/licenses/odbl/\">Open Database License</a>, tiles (C) by <a href=\"http://www.thunderforest.com/outdoors/\">Thunderforest</a>"; |
325
|
|
|
} else if (newMapType === "TOPO") { |
326
|
|
|
isGoogleMap = false; |
327
|
|
|
copyright = "Map data (C) by <a href=\"http://www.openstreetmap.org/\">OpenStreetMap.org</a> and its contributors; <a href=\"http://opendatacommons.org/licenses/odbl/\">Open Database License</a>, height data by SRTM, tiles (C) by <a href=\"http://www.opentopomap.org/\">OpenTopoMap</a>"; |
328
|
|
|
} |
329
|
|
|
|
330
|
|
|
if (copyrightDiv) { |
331
|
|
|
copyrightDiv.innerHTML = copyright; |
332
|
|
|
} |
333
|
|
|
|
334
|
|
|
if (isGoogleMap) { |
335
|
|
|
$(".gmnoprint a, .gmnoprint span, .gm-style-cc").css("display", "block"); |
336
|
|
|
$("a[href*='maps.google.com/maps']").show(); |
337
|
|
|
map.setOptions({streetViewControl: true}); |
338
|
|
|
} else { |
339
|
|
|
// hide logo for non-g-maps |
340
|
|
|
$("a[href*='maps.google.com/maps']").hide(); |
341
|
|
|
// hide term-of-use for non-g-maps |
342
|
|
|
$(".gmnoprint a, .gmnoprint span, .gm-style-cc").css("display", "none"); |
343
|
|
|
map.setOptions({streetViewControl: false}); |
344
|
|
|
} |
345
|
|
|
} |
346
|
|
|
|
347
|
|
|
|
348
|
|
|
function repairLat(x, d) { |
349
|
|
|
'use strict'; |
350
|
|
|
|
351
|
|
|
if (x === null || isNaN(x) || x < -90 || x > +90) { |
352
|
|
|
return d; |
353
|
|
|
} |
354
|
|
|
|
355
|
|
|
return x; |
356
|
|
|
} |
357
|
|
|
|
358
|
|
|
|
359
|
|
|
function repairLon(x, d) { |
360
|
|
|
'use strict'; |
361
|
|
|
|
362
|
|
|
if (x === null || isNaN(x) || x < -180 || x > +180) { |
363
|
|
|
return d; |
364
|
|
|
} |
365
|
|
|
|
366
|
|
|
return x; |
367
|
|
|
} |
368
|
|
|
|
369
|
|
|
|
370
|
|
|
function repairRadius(x, d) { |
371
|
|
|
'use strict'; |
372
|
|
|
|
373
|
|
|
if (x === null || isNaN(x) || x < 0 || x > 100000000) { |
374
|
|
|
return d; |
375
|
|
|
} |
376
|
|
|
|
377
|
|
|
return x; |
378
|
|
|
} |
379
|
|
|
|
380
|
|
|
|
381
|
|
|
function repairZoom(x, d) { |
382
|
|
|
'use strict'; |
383
|
|
|
|
384
|
|
|
if (x === null || isNaN(x) || x < 1 || x > 20) { |
385
|
|
|
return d; |
386
|
|
|
} |
387
|
|
|
|
388
|
|
|
return x; |
389
|
|
|
} |
390
|
|
|
|
391
|
|
|
|
392
|
|
|
function repairMaptype(t, d) { |
393
|
|
|
'use strict'; |
394
|
|
|
|
395
|
|
|
if (t === "OSM" || t === "OSM/DE" || t === "OCM" || t === "OUTD" || t === "TOPO" || |
396
|
|
|
t === "satellite" || t === "hybrid" || t === "roadmap" || t === "terrain") { |
397
|
|
|
return t; |
398
|
|
|
} |
399
|
|
|
|
400
|
|
|
return d; |
401
|
|
|
} |
402
|
|
|
|
403
|
|
|
|
404
|
|
|
function tileUrl(template, servers, coord, zoom) { |
405
|
|
|
'use strict'; |
406
|
|
|
|
407
|
|
|
var limit = Math.pow(2, zoom), |
408
|
|
|
x = ((coord.x % limit) + limit) % limit, |
409
|
|
|
y = coord.y, |
410
|
|
|
s = servers[(Math.abs(x + y)) % servers.length]; |
411
|
|
|
|
412
|
|
|
return template.replace(/%s/, s).replace(/%x/, x).replace(/%y/, y).replace(/%z/, zoom); |
413
|
|
|
} |
414
|
|
|
|
415
|
|
|
|
416
|
|
|
function initialize(xcenter, xzoom, xmap, xfeatures, xmarkers, xlines, xgeocache) { |
417
|
|
|
'use strict'; |
418
|
|
|
|
419
|
|
|
var center = null; |
420
|
|
|
var atDefaultCenter = false; |
|
|
|
|
421
|
|
|
var zoom = parseInt(xzoom, 10); |
422
|
|
|
var maptype = xmap; |
423
|
|
|
|
424
|
|
|
// parse markers |
425
|
|
|
var markerdata = []; |
426
|
|
|
var markercenter = null; |
427
|
|
|
{ |
428
|
|
|
var count = 0; |
429
|
|
|
var clat = 0; |
430
|
|
|
var clon = 0; |
431
|
|
|
|
432
|
|
|
// ID:COODS:R(:NAME)?|ID:COORDS:R(:NAME)? |
433
|
|
|
// COORDS=LAT:LON or DEG or DMMM |
434
|
|
|
var data; |
435
|
|
|
if (xmarkers.indexOf("*") != -1) { |
436
|
|
|
data = xmarkers.split('*'); |
437
|
|
|
} else { |
438
|
|
|
/*if (xmarkers.indexOf("|") != -1)*/ |
439
|
|
|
data = xmarkers.split('|'); |
440
|
|
|
} |
441
|
|
|
|
442
|
|
|
for (var i = 0; i != data.length; i += 1) { |
443
|
|
|
var data2 = data[i].split(':'); |
444
|
|
|
if (data2.length < 3 || data2.length > 5) continue; |
|
|
|
|
445
|
|
|
|
446
|
|
|
var m = new Object(); |
447
|
|
|
m.alpha = data2[0]; |
448
|
|
|
m.id = alpha2id(m.alpha); |
449
|
|
|
if (m.id == -1) continue; |
|
|
|
|
450
|
|
|
m.name = null; |
451
|
|
|
|
452
|
|
|
var index = 1; |
453
|
|
|
var lat = parseFloat(data2[index]); |
454
|
|
|
var lon = parseFloat(data2[index+1]); |
455
|
|
|
if (lat != null && lon != null && -90 <= lat && lat <= 90 && -180 <= lon && lon <= 180) { |
456
|
|
|
index = index + 2; |
457
|
|
|
m.coords = new google.maps.LatLng(lat, lon); |
458
|
|
|
} else { |
459
|
|
|
m.coords = Coordinates.fromString(data2[index]); |
460
|
|
|
if (m.coords == null) continue; |
|
|
|
|
461
|
|
|
index = index + 1; |
462
|
|
|
} |
463
|
|
|
|
464
|
|
|
var circle = parseFloat(data2[index]); |
465
|
|
|
if (circle < 0 || circle > 100000000000) continue; |
|
|
|
|
466
|
|
|
m.r = circle; |
467
|
|
|
index = index + 1; |
468
|
|
|
|
469
|
|
|
if (index < data2.length) { |
470
|
|
|
if (/^([a-zA-Z0-9-_]*)$/.test(data2[index])) { |
471
|
|
|
m.name = data2[index]; |
472
|
|
|
} |
473
|
|
|
} |
474
|
|
|
|
475
|
|
|
count += 1; |
476
|
|
|
clat += m.coords.lat(); |
477
|
|
|
clon += m.coords.lng(); |
478
|
|
|
|
479
|
|
|
markerdata.push(m); |
480
|
|
|
} |
481
|
|
|
|
482
|
|
|
if (count != 0) { |
483
|
|
|
markercenter = new google.maps.LatLng(clat / count, clon / count); |
484
|
|
|
} |
485
|
|
|
} |
486
|
|
|
|
487
|
|
|
var loadfromcookies = false; |
488
|
|
|
if (xcenter != null && xcenter != '') { |
489
|
|
|
var data = xcenter.split(':'); |
|
|
|
|
490
|
|
|
|
491
|
|
|
if (data.length == 1) { |
492
|
|
|
center = Coordinates.fromString(xcenter); |
493
|
|
|
} else { |
494
|
|
|
var lat = parseFloat(data[0]); |
|
|
|
|
495
|
|
|
var lon = parseFloat(data[1]); |
|
|
|
|
496
|
|
|
|
497
|
|
|
if (lat >= -90 && lat <= 90 && lon >= -180 && lon <= 180) { |
498
|
|
|
center = new google.maps.LatLng(lat, lon); |
499
|
|
|
} |
500
|
|
|
} |
501
|
|
|
} else if (markercenter != null) { |
502
|
|
|
center = markercenter; |
503
|
|
|
} else { |
504
|
|
|
loadfromcookies = true; |
505
|
|
|
|
506
|
|
|
/* try to read coordinats from cookie */ |
507
|
|
|
clat = get_cookie_float('clat', CLAT_DEFAULT); |
508
|
|
|
clon = get_cookie_float('clon', CLON_DEFAULT); |
509
|
|
|
if (clat == CLAT_DEFAULT && clon == CLON_DEFAULT) { |
510
|
|
|
atDefaultCenter = true; |
511
|
|
|
} |
512
|
|
|
|
513
|
|
|
clat = repairLat(clat, CLAT_DEFAULT); |
514
|
|
|
clon = repairLon(clon, CLON_DEFAULT); |
515
|
|
|
center = new google.maps.LatLng(clat, clon); |
516
|
|
|
|
517
|
|
|
zoom = get_cookie_int('zoom', ZOOM_DEFAULT); |
518
|
|
|
maptype = get_cookie_string('maptype', MAPTYPE_DEFAULT); |
519
|
|
|
} |
520
|
|
|
|
521
|
|
|
if (center == null) { |
522
|
|
|
center = new google.maps.LatLng(CLAT_DEFAULT, CLON_DEFAULT); |
523
|
|
|
atDefaultCenter = true; |
524
|
|
|
} |
525
|
|
|
|
526
|
|
|
zoom = repairZoom(zoom, ZOOM_DEFAULT); |
527
|
|
|
maptype = repairMaptype(maptype, MAPTYPE_DEFAULT); |
528
|
|
|
|
529
|
|
|
var myOptions = { |
530
|
|
|
zoom: zoom, |
531
|
|
|
center: center, |
532
|
|
|
scaleControl: true, |
533
|
|
|
streetViewControl: false, |
534
|
|
|
mapTypeControlOptions: { mapTypeIds: ['OSM', 'OSM/DE', 'OCM', 'OUTD', 'TOPO', google.maps.MapTypeId.ROADMAP, google.maps.MapTypeId.SATELLITE, google.maps.MapTypeId.HYBRID, google.maps.MapTypeId.TERRAIN] }, |
535
|
|
|
mapTypeId: google.maps.MapTypeId.ROADMAP }; |
536
|
|
|
|
537
|
|
|
map = new google.maps.Map(document.getElementById("themap"), myOptions); |
538
|
|
|
|
539
|
|
|
var osm_type = new google.maps.ImageMapType({ |
540
|
|
|
getTileUrl: function(coord, zoom) { |
541
|
|
|
return tileUrl("http://%s.tile.openstreetmap.org/%z/%x/%y.png", ["a","b","c"], coord, zoom); |
542
|
|
|
}, |
543
|
|
|
tileSize: new google.maps.Size(256, 256), |
544
|
|
|
name: "OSM", |
545
|
|
|
alt: "OpenStreetMap", |
546
|
|
|
maxZoom: 18 }); |
547
|
|
|
var osmde_type = new google.maps.ImageMapType({ |
548
|
|
|
getTileUrl: function(coord, zoom) { |
549
|
|
|
return tileUrl("http://%s.tile.openstreetmap.de/tiles/osmde/%z/%x/%y.png", ["a","b","c"], coord, zoom); |
550
|
|
|
}, |
551
|
|
|
tileSize: new google.maps.Size(256, 256), |
552
|
|
|
name: "OSM/DE", |
553
|
|
|
alt: "OpenStreetMap (german style)", |
554
|
|
|
maxZoom: 18 }); |
555
|
|
|
var ocm_type = new google.maps.ImageMapType({ |
556
|
|
|
getTileUrl: function(coord, zoom) { |
557
|
|
|
return tileUrl("http://%s.tile.opencyclemap.org/cycle/%z/%x/%y.png", ["a","b","c"], coord, zoom); |
558
|
|
|
}, |
559
|
|
|
tileSize: new google.maps.Size(256, 256), |
560
|
|
|
name: "OCM", |
561
|
|
|
alt: "OpenCycleMap", |
562
|
|
|
maxZoom: 17 }); |
563
|
|
|
var outdoors_type = new google.maps.ImageMapType({ |
564
|
|
|
getTileUrl: function(coord, zoom) { |
565
|
|
|
return tileUrl("http://%s.tile.thunderforest.com/outdoors/%z/%x/%y.png", ["a","b","c"], coord, zoom); |
566
|
|
|
}, |
567
|
|
|
tileSize: new google.maps.Size(256, 256), |
568
|
|
|
name: "OUTD", |
569
|
|
|
alt: "Thunderforest Outdoors", |
570
|
|
|
maxZoom: 18 }); |
571
|
|
|
var topomap_type = new google.maps.ImageMapType({ |
572
|
|
|
getTileUrl: function(coord, zoom) { |
573
|
|
|
return tileUrl("https://%s.tile.opentopomap.org/%z/%x/%y.png", ["a","b","c"], coord, zoom); |
574
|
|
|
}, |
575
|
|
|
tileSize: new google.maps.Size(256, 256), |
576
|
|
|
name: "TOPO", |
577
|
|
|
alt: "OpenTopoMap", |
578
|
|
|
maxZoom: 15 }); |
579
|
|
|
|
580
|
|
|
map.mapTypes.set("OSM", osm_type); |
581
|
|
|
map.mapTypes.set("OSM/DE", osmde_type); |
582
|
|
|
map.mapTypes.set("OCM", ocm_type); |
583
|
|
|
map.mapTypes.set("OUTD", outdoors_type); |
584
|
|
|
map.mapTypes.set("TOPO", topomap_type); |
585
|
|
|
map.setMapTypeId(maptype); |
586
|
|
|
|
587
|
|
|
Sidebar.init(map); |
|
|
|
|
588
|
|
|
ExternalLinks.init(map); |
|
|
|
|
589
|
|
|
Lines.init(map); |
590
|
|
|
Geolocation.init(map); |
|
|
|
|
591
|
|
|
Hillshading.init(map); |
|
|
|
|
592
|
|
|
NPA.init(map); |
|
|
|
|
593
|
|
|
CDDA.init(map); |
|
|
|
|
594
|
|
|
Freifunk.init(map); |
|
|
|
|
595
|
|
|
|
596
|
|
|
//boundariesLayer = new google.maps.ImageMapType({ |
597
|
|
|
// getTileUrl: function(coord, zoom) { |
598
|
|
|
// if (6 <= zoom && zoom <= 16) |
599
|
|
|
// { |
600
|
|
|
// return tileUrl("http://korona.geog.uni-heidelberg.de/tiles/adminb/?x=%x&y=%y&z=%z", ["dummy"], coord, zoom); |
601
|
|
|
// } |
602
|
|
|
// else |
603
|
|
|
// { |
604
|
|
|
// return null; |
605
|
|
|
// } |
606
|
|
|
// }, |
607
|
|
|
// tileSize: new google.maps.Size(256, 256), |
608
|
|
|
// name: "adminb", |
609
|
|
|
// alt: "Administrative Boundaries", |
610
|
|
|
// maxZoom: 16 }); |
611
|
|
|
|
612
|
|
|
// Create div for showing copyrights. |
613
|
|
|
copyrightDiv = document.createElement("div"); |
614
|
|
|
copyrightDiv.id = "map-copyright"; |
615
|
|
|
copyrightDiv.style.fontSize = "11px"; |
616
|
|
|
copyrightDiv.style.fontFamily = "Arial, sans-serif"; |
617
|
|
|
copyrightDiv.style.margin = "0 2px 2px 0"; |
618
|
|
|
copyrightDiv.style.whiteSpace = "nowrap"; |
619
|
|
|
copyrightDiv.style.background = "#FFFFFF"; |
620
|
|
|
map.controls[google.maps.ControlPosition.BOTTOM_RIGHT].push(copyrightDiv); |
621
|
|
|
|
622
|
|
|
map.setCenter(center, zoom); |
623
|
|
|
|
624
|
|
|
google.maps.event.addListener(map, "center_changed", function() { storeZoom(); storeCenter(); okapi_schedule_load_caches(); }); |
625
|
|
|
google.maps.event.addListener(map, "zoom_changed", function() { storeZoom(); storeCenter(); okapi_schedule_load_caches(); }); |
626
|
|
|
google.maps.event.addListener(map, "maptypeid_changed", function(){ updateCopyrights()}); |
627
|
|
|
|
628
|
|
|
if (loadfromcookies) { |
629
|
|
|
var raw_ids = Cookies.get('markers'); |
630
|
|
|
if (raw_ids != undefined) { |
631
|
|
|
var ids = raw_ids.split(':'); |
632
|
|
|
for (var i = 0; i != ids.length; ++i) { |
|
|
|
|
633
|
|
|
var id = parseInt(ids[i], 10); |
634
|
|
|
if (id === null || id < 0 || id >= 26*10) continue; |
|
|
|
|
635
|
|
|
|
636
|
|
|
var raw_data = Cookies.get('marker' + id); |
637
|
|
|
if (raw_data == undefined) continue; |
|
|
|
|
638
|
|
|
|
639
|
|
|
var data = raw_data.split(':') |
|
|
|
|
640
|
|
|
if (data.length != 3 && data.length != 4) continue; |
|
|
|
|
641
|
|
|
|
642
|
|
|
var lat = parseFloat(data[0]); |
|
|
|
|
643
|
|
|
if (lat < -90 || lat > 90) continue; |
|
|
|
|
644
|
|
|
var lon = parseFloat(data[1]); |
|
|
|
|
645
|
|
|
if (lon < -180 || lon > 180) continue; |
|
|
|
|
646
|
|
|
var r = parseFloat(data[2]); |
647
|
|
|
if (r < 0 || r > 100000000000) continue; |
|
|
|
|
648
|
|
|
|
649
|
|
|
var name = null; |
650
|
|
|
if (data.length == 4) { |
651
|
|
|
if (/^([a-zA-Z0-9-_]*)$/.test(data[3])) { |
652
|
|
|
name = data[3]; |
653
|
|
|
} |
654
|
|
|
} |
655
|
|
|
|
656
|
|
|
newMarker(new google.maps.LatLng(lat, lon), id, r, name); |
657
|
|
|
} |
658
|
|
|
} |
659
|
|
|
|
660
|
|
|
var raw_lines = Cookies.get('lines'); |
661
|
|
|
if (raw_lines != undefined) { |
662
|
|
|
var linesarray = raw_lines.split('*'); |
663
|
|
|
for (var i = 0; i < linesarray.length; ++i) { |
|
|
|
|
664
|
|
|
var line = linesarray[i].split(':'); |
665
|
|
|
if (line.length != 2) continue; |
|
|
|
|
666
|
|
|
|
667
|
|
|
var id1 = alpha2id(line[0]); |
668
|
|
|
if (id1 != -1 && theMarkers.getById(id1).isFree()) { |
669
|
|
|
id1 = -1; |
670
|
|
|
} |
671
|
|
|
var id2 = alpha2id(line[1]); |
672
|
|
|
if (id2 != -1 && theMarkers.getById(id2).isFree()) { |
673
|
|
|
id2 = -1; |
674
|
|
|
} |
675
|
|
|
|
676
|
|
|
Lines.newLine(id1, id2); |
677
|
|
|
} |
678
|
|
|
} |
679
|
|
|
} else { |
680
|
|
|
for (var i = 0; i < markerdata.length; ++i) { |
|
|
|
|
681
|
|
|
newMarker(markerdata[i].coords, markerdata[i].id, markerdata[i].r, markerdata[i].name); |
682
|
|
|
} |
683
|
|
|
|
684
|
|
|
var raw_lines = xlines; |
|
|
|
|
685
|
|
|
if (raw_lines != null) { |
686
|
|
|
/* be backwards compatible */ |
687
|
|
|
if (raw_lines.length == 3 |
688
|
|
|
&& raw_lines[0] >= 'A' && raw_lines[0] <= 'Z' |
689
|
|
|
&& raw_lines[1] == '*' |
690
|
|
|
&& raw_lines[2] >= 'A' && raw_lines[2] <= 'Z') { |
691
|
|
|
raw_lines = raw_lines[0] + ':' + raw_lines[2]; |
692
|
|
|
} |
693
|
|
|
|
694
|
|
|
var linesarray = raw_lines.split('*'); |
|
|
|
|
695
|
|
|
for (var i = 0; i < linesarray.length; ++i) { |
|
|
|
|
696
|
|
|
var line = linesarray[i].split(':'); |
|
|
|
|
697
|
|
|
if (line.length != 2) continue; |
|
|
|
|
698
|
|
|
|
699
|
|
|
var id1 = alpha2id(line[0]); |
|
|
|
|
700
|
|
|
if (id1 != -1 && theMarkers.getById(id1).isFree()) { |
701
|
|
|
id1 = -1; |
702
|
|
|
} |
703
|
|
|
var id2 = alpha2id(line[1]); |
|
|
|
|
704
|
|
|
if (id2 != -1 && theMarkers.getById(id2).isFree()) { |
705
|
|
|
id2 = -1; |
706
|
|
|
} |
707
|
|
|
|
708
|
|
|
Lines.newLine(id1, id2); |
709
|
|
|
} |
710
|
|
|
} |
711
|
|
|
} |
712
|
|
|
|
713
|
|
|
okapi_show_cache = xgeocache; |
|
|
|
|
714
|
|
|
Sidebar.restore(true); |
|
|
|
|
715
|
|
|
if (xfeatures == '[default]') { |
716
|
|
|
Hillshading.restore(false); |
|
|
|
|
717
|
|
|
//restoreBoundaries(false); |
718
|
|
|
restoreGeocaches(false); |
719
|
|
|
NPA.toggle(false); |
|
|
|
|
720
|
|
|
CDDA.toggle(false); |
|
|
|
|
721
|
|
|
Freifunk.toggle(false); |
|
|
|
|
722
|
|
|
} else { |
723
|
|
|
Hillshading.toggle(xfeatures.indexOf('h') >= 0 || xfeatures.indexOf('H') >= 0); |
724
|
|
|
//toggleBoundaries(xfeatures.indexOf('b') >= 0 || xfeatures.indexOf('B') >= 0); |
725
|
|
|
okapi_toggle_load_caches(xfeatures.indexOf('g') >= 0 || xfeatures.indexOf('G') >= 0); |
726
|
|
|
NPA.toggle(xfeatures.indexOf('n') >= 0 || xfeatures.indexOf('N') >= 0); |
727
|
|
|
Freifunk.toggle(xfeatures.indexOf('f') >= 0 || xfeatures.indexOf('F') >= 0); |
728
|
|
|
} |
729
|
|
|
restoreCoordinatesFormat(0); |
730
|
|
|
|
731
|
|
|
if (xgeocache != "") { |
732
|
|
|
okapi_toggle_load_caches(true); |
733
|
|
|
atDefaultCenter = false; |
|
|
|
|
734
|
|
|
} |
735
|
|
|
|
736
|
|
|
// update copyrights + gmap-stuff now, once the map is fully loaded, and in 1s - just to be sure! |
737
|
|
|
updateCopyrights(); |
738
|
|
|
google.maps.event.addListenerOnce(map, 'idle', function(){ updateCopyrights(); }); |
739
|
|
|
setTimeout(function(){ updateCopyrights(); }, 1000); |
740
|
|
|
|
741
|
|
|
//if (atDefaultCenter) { |
742
|
|
|
// Geolocation.whereAmI(); |
743
|
|
|
//} |
744
|
|
|
} |
745
|
|
|
|